define([
    'backbone',
    'template',
    'jquery',
    'text!indexHtml'
], function(B,template,$,html) {
    var indexView=B.View.extend({
        el:$('#container'),
        template:template.compile(html),
        initialize:function(){
            this.render();
        },
        render:function(){
            var arr=this.collection.models.map(function(item){
                return item.toJSON();
            })
            this.$el.html(this.template({models:arr}));
        },
        events:{
            'click #deleteBtn':'deleteHandle'
        },
        deleteHandle:function(e){
            if (confirm('确定要删除吗？')) {
                var id=$(e.target).attr('data-id');
                var that=this;
                var model=this.collection.get(id);
                if (!!model) {
                    model.destroy().done(function(){
                        that.render();
                    })
                }
            }
        }
    })
    return indexView;
});